package cn.edu.gzmtu.controller;

import cn.edu.gzmtu.domain.Permission;
import cn.edu.gzmtu.service.IPermissionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PatchMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;

import java.util.List;

/**
 * 权限管理
 */
@Controller
@RequestMapping("/permission")
public class PermissionController {

    @Autowired
    private IPermissionService permissionService;

    /**
     * 查询所有
     * @return
     * @throws Exception
     */
    @RequestMapping("/findAll.do")
    public ModelAndView findAll() throws Exception {

        List<Permission> permissionList = permissionService.findAll();

        ModelAndView mv = new ModelAndView();
        mv.addObject("permissionList", permissionList);
        mv.setViewName("permission-list");

        return mv;
    }

    /**
     * 添加资源权限
     */
    @RequestMapping("save.do")
    public String save(Permission permission) throws Exception {

        permissionService.save(permission);

        return "redirect:findAll.do";
    }
}
